var Md5 = require('../../utils/md5.js');
var timeSecond = Math.floor(Date.now() * 0.001);  //获取时间戳: 
var SignInfoData = Md5.hexMD5(timeSecond + 'nativetalk')//md5加密;
var httpFile = 'http://file.waijiaojun.com/';
const app = getApp();
var httpNativetalk = app.globalData.httpNativetalk;
var httpWeike = app.globalData.httpWeike;
var categoryId ;
Page({
  data: {
    topClassType: ['日常口语', '托福课程', '雅思课程', '商务英语', '青少儿英语', '学术英语', '西班牙语', '日语'],
    topClassTypeidx: 0,
    imgUrl: 'http://file.waijiaojun.com/waijiaojun/icon',
  },
  onLoad:function(){

  },
  onShow: function () {
    this.topClassTypesFun();
  },

  topClassTypesFun: function (e) {
    var that = this;
    console.log(e)
    if (e==undefined){
      var index = 0;
      that.tryClassData(1);
    }else{    
    var index = e.currentTarget.dataset.dix;
    console.log('index='+index);
    that.setData({
      topClassTypeidx: index,
    });   

    if(index == 0){
      categoryId = 1;
      console.log("index="+index+",categoryId=" + categoryId);
    }else if(index == 1){
      categoryId = 7;
      console.log("index=" + index + ",categoryId=" + categoryId);
    }
    else if (index == 2) {
      categoryId = 41;
      console.log("index=" + index + ",categoryId=" + categoryId);
    }
    else if (index == 3) {
      categoryId = 34;
      console.log("index=" + index + ",categoryId=" + categoryId);
    }
    else if (index == 4) {
      categoryId = 12;
    }
    else if (index == 5) {
      categoryId = 43;
    }
    else if (index == 6) {
      categoryId = 42;
    }
    else if (index == 7) {
      categoryId = 44;
    }
    that.tryClassData(categoryId);
    }
  },
  //数据内容的请求
  tryClassData: function (categoryId) {
    var that = this;
    wx.request({
      url: httpNativetalk + '/app/15/token/experience/courseList',
      data: {
        "categoryId": categoryId,
      },
      header: {
        "Timestamp": timeSecond,
        "SignInfo": SignInfoData,
        "content-Type": "application/json",
        "client_type": "3",
        "version": 15,
        "token": app.globalData.token,
      },
      method: 'POSt',
      dataType: 'json',
      success: function (res) {
        console.log(res)
        that.setData({
          course: res.data.obj,
        })
      },
      fail: function (res) { },
      complete: function (res) { },
    })
  },
  toClassDetailFun: function (e) {
    var classIds = e.currentTarget.dataset.idx;
    var titleData = e.currentTarget.dataset.titles;
    wx.navigateTo({
      url: '/pages/classDetail/classDetail?classId=' + classIds,
    });
    wx.setNavigationBarTitle({
      title: titleData,
    })
  },
  // onUnload: function () {
  //   categoryId = 1;
  //   this.tryClassData(categoryId);
  // },
})